//============================================
// Define VDD and VSS
//============================================
VVDD (VDD 0) vsource dc=pvdd
VVDDC (VDDC 0) vsource dc=pvddc
VVDDR (VDDR 0) vsource dc=pvdd
VVDD2 (VDD2 0) vsource dc=pvdd
VVSS (VSS 0) vsource dc=0
VVBP (VBP 0) vsource dc=pvbp
VVBN (VBN 0) vsource dc=pvbn

VIN (IN 0) vsource type=pulse val0=0 val1=pvdd rise=prise fall=pfall width=pwidth period=pper

//Inverter
subckt Inv (Input Output VDD VSS VBN VBP)
P1 (VDD Input Output VBP) P_TRANSISTOR width=wdef length=ldef
N1 (VSS Input Output VBN) N_TRANSISTOR width=wdef length=ldef
ends Inv

//Driver
subckt Driver (Input Output VDD VSS VBN VBP)
P1 (VDD Input A VBP) P_TRANSISTOR width=10*wdef length=ldef
N1 (VSS Input A VBN) N_TRANSISTOR width=10*wdef length=ldef
P2 (VDD A Output VBP) P_TRANSISTOR width=10*wdef length=ldef
N2 (VSS A Output VBN) N_TRANSISTOR width=10*wdef length=ldef
ends Driver

//Switch (Pass Gate)
subckt PGSwitch (Input Output VDD VDDc VSS VBN VBP)
N (Input VDDc Output VBN) N_TRANSISTOR width=10*wdef length=ldef
ends PGSwitch

//Switch (Transmission Gate)
subckt TXSwitch (Input Output VDD VDDc VSS VBN VBP)
N (Input VDDc Output VBN) N_TRANSISTOR width=wdef length=ldef
P (Input VSS Output VBP) P_TRANSISTOR width=wdef length=ldef
ends TXSwitch

//Switch (Tri-State Buffer)
subckt TSSwitch (Input Output VDD VDDc VSS VBN VBP)
P1 (A Input VDD VBP) P_TRANSISTOR width=5*wdef length=ldef
N1 (A Input VSS VBN) N_TRANSISTOR width=5*wdef length=ldef
P2 (B A VDD VBP) P_TRANSISTOR width=5*wdef length=ldef
N2 (B A VSS VBN) N_TRANSISTOR width=5*wdef length=ldef
NC (B VDDc Output VBN) N_TRANSISTOR width=wdef length=ldef
ends TSSwitch

//Switchbox
subckt Switchbox (Input Output VDD VDDc VSS VBN VBP)
S1 (Input A VDD VDDc VSS VBN VBP) PGSwitch
Soff1 (Input off1 VDD VSS VSS VBN VBP) PGSwitch
Soff2 (Input off2 VDD VSS VSS VBN VBP) PGSwitch
Soff3 (A off3 VDD VSS VSS VBN VBP) PGSwitch
Soff4 (A off4 VDD VSS VSS VBN VBP) PGSwitch
R (A Output) resistor r=50
C (Output VSS) capacitor c=13f
Roff1 (off1 off_1) resistor r=50
Coff1 (off_1 VSS) capacitor c=13f
Roff2 (off2 off_2) resistor r=50
Coff2 (off_2 VSS) capacitor c=13f
Roff3 (off3 off_3) resistor r=50
Coff3 (off_3 VSS) capacitor c=13f
Roff4 (off4 off_4) resistor r=50
Coff4 (off_4 VSS) capacitor c=13f
ends Switchbox

//Connection Box (Depends on Channel Width)
subckt Connectionbox (Input Output VDD VDDc VSS VBN VBP)
S (Input A VDD VDDc VSS VBN VBP) PGSwitch
R (A Output) resistor r=50
C (Output VSS) capacitor c=13f
Soff1 (Input OFF1 VDD VDDc VSS VBN VBP) PGSwitch
R1 (OFF1 OUT1) resistor r=50
C1 (OUT1 VSS) capacitor c=13f
Soff2 (Input OFF2 VDD VDDc VSS VBN VBP) PGSwitch
R2 (OFF2 OUT2) resistor r=50
C2 (OUT2 VSS) capacitor c=13f
Soff3 (Input OFF3 VDD VDDc VSS VBN VBP) PGSwitch
R3 (OFF3 OUT3) resistor r=50
C3 (OUT3 VSS) capacitor c=13f
Soff4 (Input OFF4 VDD VDDc VSS VBN VBP) PGSwitch
R4 (OFF4 OUT4) resistor r=50
C4 (OUT4 VSS) capacitor c=13f
ends Connectionbox

//Sense Amp (ASA w/o hysteresis)
subckt CSA1 (Input Output VDD VSS VBN VBP)
SA_EN (Input VSS VSS VBN) N_TRANSISTOR width=wdef length=ldef
SA_N1 (X Input VSS VBN) N_TRANSISTOR width=wdef length=ldef
SA_N2 (Output X D VBN) N_TRANSISTOR width=wdef length=ldef
SA_N3 (D X VSS VBN) N_TRANSISTOR width=wdef length=ldef
SA_P1 (A Input VDD VBP) P_TRANSISTOR width=wdef length=ldef
SA_P2 (B Input A VBP) P_TRANSISTOR width=wdef length=ldef
SA_P3 (C Input B VBP) P_TRANSISTOR width=wdef length=ldef
SA_P4 (X Input C VBP) P_TRANSISTOR width=wdef length=ldef
SA_P5 (Output X VDD VBP) P_TRANSISTOR width=wdef length=ldef
ends CSA1

//Sense Amp (Joe's ASA)
subckt ASA (Input Output VDD VSS VBN VBP)
SA_EN (Input VSS VSS VBN) N_TRANSISTOR width=wdef length=ldef
SA_N1 (X Input VSS VBN) N_TRANSISTOR width=wdef length=ldef
SA_N2 (Output X D VBN) N_TRANSISTOR width=wdef length=ldef
SA_N3 (D X VSS VBN) N_TRANSISTOR width=wdef length=ldef
SA_P1 (A Input VDD VBP) P_TRANSISTOR width=wdef length=ldef
SA_P2 (B Input A VBP) P_TRANSISTOR width=wdef length=ldef
SA_P3 (C Input B VBP) P_TRANSISTOR width=wdef length=ldef
SA_P4 (X Input C VBP) P_TRANSISTOR width=wdef length=ldef
SA_P5 (Output X VDD VBP) P_TRANSISTOR width=wdef length=ldef
SA_P6 (B X VSS VBP) P_TRANSISTOR width=wdef length=ldef
ends ASA

//FO4 Output
subckt FO4 (OUT VDD VSS VBN VBP)
FOUT1 (OUT OUTFO1 VDD VSS VBN VBP) Inv
FOUT2 (OUT OUTFO2 VDD VSS VBN VBP) Inv
FOUT3 (OUT OUTFO3 VDD VSS VBN VBP) Inv
FOUT4 (OUT OUTFO4 VDD VSS VBN VBP) Inv
ends FO4

//Net

